package com.qingke.besuper.command.impl;

import com.qingke.besuper.command.UserCommand;
import com.qingke.besuper.pojo.Question;
import com.qingke.besuper.pojo.User;
import com.qingke.besuper.util.BeSuperConsole;

public class ListQuestionByQuestionIdCommand extends UserCommand implements ListAnswersByQuestionId{

	public ListQuestionByQuestionIdCommand(User user) {
		super(user);
	}

	@Override
	public void execute() {
		int idInt=-1;
		String idStr="";
		while(true){
			idStr=BeSuperConsole.promptNotEmpty("input the question's id:").trim();
			if(idStr.replaceAll("[0-9]","").equals("")){
				idInt=Integer.parseInt(idStr);
			}
			else{
				BeSuperConsole.println("err input");
				continue;
			}
			break;
		}
		Question q=dao.getQuestionByQuestionId(idInt);
		
		if(q!=null){
			BeSuperConsole.println("------the id of the question------");
			int bestAnswerId=q.getBestAnswerId();
			if(bestAnswerId==-1){
				BeSuperConsole.println("id:["+q.getId()+"],credit:["+q.getCredit()+"],questioner:["+q.getPlayerId()+"],isOpen:["+q.isOpen()+"],context:"+q.getContext());
			}
			else{
				BeSuperConsole.println("id:["+q.getId()+"],credit:["+q.getCredit()+"],questioner:["+q.getPlayerId()+"],bset answer id:["+q.getBestAnswerId()+"],isOpen:["+q.isOpen()+"],context:"+q.getContext());
			}
			
			ListAnswersByQuestionIdCommand(q.getId());
		}
		else{
			BeSuperConsole.println("the id of the question is not exited.");
		}
	}

}
